package com.yjzx.util.service.http.bean;

import com.alibaba.fastjson.JSONObject;
import com.yjzx.util.common.util.SeqUtil;
import com.yjzx.util.common.util.encrypt.AES;
import com.yjzx.util.common.util.encrypt.HmacMd5;
import com.yjzx.util.common.util.TimeUtils;

/**
 * @author yjzx
 * @date 2024/6/3
 * @description BaseParam
 */
public abstract class BaseParam {
    private AuthKey authKey;

    public AuthKey getAuthKey() {
        return authKey;
    }

    public Body makeBody() {
        padding();
        check();
        Body body = new Body();

        String dataString = AES.encrypt(JSONObject.toJSONString(this), authKey.getOutDataSecret(), authKey.getOutDataSecretIv());
        body.setData(dataString);
        body.setTimeStamp(TimeUtils.getTimeStamp());
        body.setSeq(SeqUtil.getSeq());
        //拼接数据 计算签名
        String builder =  body.getData() + body.getTimeStamp() + body.getSeq();
        //设置签名
        body.setSig(HmacMd5.createSign(builder, authKey.getOutSigSecret()));
        return body;
    }

    /**
     * 填充数据
     */
    public abstract void padding();

    /**
     * uri
     * @return
     */
    public abstract String uri();

    /**
     * 校验参数
     */
    public abstract void check();
}
